package com.hunk.core.auth.entity;

import java.util.HashSet;
import java.util.Set;

import com.hunk.core.Constants;
import com.hunk.core.entity.UUIDEntity;

/** Menu
 * Description :<br>
 * 
 * @author HunkDeng
 * @since 2013-4-13
 */
public class Menu extends UUIDEntity {

	private static final long serialVersionUID = -7471483709168160581L;
	
    private String functionName;

    private String functionCode;

    private String description;

    private String functionUrl;

    private Integer ordinal;

    private Menu parentFunction;

    private Set<Menu> childFunctions = new HashSet<Menu>();

	public String getFunctionName() {
        return functionName;
    }

    public void setFunctionName(String functionName) {
        this.functionName = functionName;
    }

    public String getFunctionCode() {
        return functionCode;
    }

    public void setFunctionCode(String functionCode) {
        this.functionCode = functionCode;
    }

    public String getFunctionUrl() {
        return functionUrl;
    }

    public void setFunctionUrl(String functionUrl) {
    	if(functionUrl != null)
    		this.functionUrl = functionUrl.trim();
    }

    public Integer getOrdinal() {
        return ordinal;
    }

    public void setOrdinal(Integer ordinal) {
        this.ordinal = ordinal;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Menu getParentFunction() {
        return parentFunction;
    }

    public void setParentFunction(Menu parentFunction) {
        this.parentFunction = parentFunction;
    }
    
    public Set<Menu> getChildFunctions() {
		return childFunctions;
	}

	public void setChildFunctions(Set<Menu> childFunctions) {
		this.childFunctions = childFunctions;
	}

	public String getNewFunctionURL(){
        if(this.getFunctionUrl() == null
                || this.getFunctionUrl().equals("")
                || this.getFunctionUrl().equals("#"))
            return this.getFunctionUrl();
        //修改URL加入 functionId 和 salt随机数
        String[] strs = this.getFunctionUrl().split("\\?");
        String urlSeparator = strs.length > 1 ? "&" : "?";
        return new StringBuilder()
                .append(this.getFunctionUrl())
                .append(urlSeparator)
                .append(Constants.FUNCTION_ID_URL_PARAMETER.name())
                .append("=")
                .append(this.getId())
                .toString();
    }
}
